Skip to content

gh-130824: Add tests for NULL in PyLong_*AndOverflow functions#130828

Merged
encukou merged 4 commits into
python:mainfrom
ZeroIntensity:add-pylong-null-checks
Mar 5, 2025
Merged

gh-130824: Add tests for NULL in PyLong_*AndOverflow functions#130828
encukou merged 4 commits into
python:mainfrom
ZeroIntensity:add-pylong-null-checks

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Mar 4, 2025

Copy link
Copy Markdown
Member

It crashed before because the assertion didn't realize that overflow would be 0 and not -1 in SystemError cases.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Few nitpicks, feel free to ignore.

Comment thread Lib/test/test_capi/test_long.py Outdated
Comment thread Modules/_testlimitedcapi/long.c
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Comment thread Lib/test/test_capi/test_long.py Outdated
self.assertEqual(func(max_val + 1), (-1, +1))
self.assertRaises(SystemError, func, None)

# CRASHES func(1.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really crash?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it doesn't: "If any other exception occurs set *overflow to 0 and return -1 as usual." TypeError will be here.

if (value == -1 && PyErr_Occurred()) {
assert(overflow == -1);
// overflow can be 0 if a seperate exception occurred
assert(overflow == -1 || overflow == 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not it always 0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not with OverflowError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OverflowError is -1 and then other exceptions (only SystemError?) are 0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only SystemError?

No, TypeError too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OverflowError is not raised. In case of an integer overflow, *overflow should be 1 or -1.

Isn't it always 0 here?

@serhiy-storchaka serhiy-storchaka self-requested a review March 4, 2025 15:50
@skirpichev skirpichev self-requested a review March 5, 2025 00:26

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one grammar nitpick

Comment thread Modules/_testlimitedcapi/long.c Outdated
Comment thread Modules/_testlimitedcapi/long.c Outdated
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@encukou encukou merged commit 9013080 into python:main Mar 5, 2025
@encukou encukou added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Mar 5, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @ZeroIntensity and @encukou, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 90130807d9c5a55b2a64024f5dfbee4785b9a27c 3.12

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2025
…ons (pythonGH-130828)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@bedevere-app

bedevere-app Bot commented Mar 5, 2025

Copy link
Copy Markdown

GH-130869 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Mar 5, 2025
@ZeroIntensity ZeroIntensity deleted the add-pylong-null-checks branch March 5, 2025 10:24
@ZeroIntensity

Copy link
Copy Markdown
Member Author

@encukou Should I make the manual backport to 3.12? I'm not sure it's worth backporting to prevent conflicts if there's already a conflict.

@serhiy-storchaka

Copy link
Copy Markdown
Member

It will help to backport future tests. It will help to ensure that no regressions be introduced in old versions.

See also #130871. You can include that change in the backports.

encukou pushed a commit to encukou/cpython that referenced this pull request Mar 5, 2025
… functions (pythonGH-130828)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@bedevere-app

bedevere-app Bot commented Mar 5, 2025

Copy link
Copy Markdown

GH-130876 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Mar 5, 2025
@encukou

encukou commented Mar 5, 2025

Copy link
Copy Markdown
Member

Should I make the manual backport to 3.12?

Sorry, I did it before I saw your message

ZeroIntensity added a commit to ZeroIntensity/cpython that referenced this pull request Mar 5, 2025
… functions (pythonGH-130828)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Mar 5, 2025
…ions (GH-130828) (GH-130869)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Mar 5, 2025
…GH-130828) (GH-130876)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants